"""Definition of the Red content type
"""

from zope.interface import implements, directlyProvides

from Products.Archetypes import atapi
from Products.ATContentTypes.content import base
from Products.ATContentTypes.content import schemata

from guegue.alcaldias import alcaldiasMessageFactory as _
from guegue.alcaldias.interfaces import IRed
from guegue.alcaldias.config import PROJECTNAME

RedSchema = schemata.ATContentTypeSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-
    atapi.StringField('title',
                searchable=1,
                isMetadata=0,
                accessor='Title',
                widget=atapi.StringWidget(label='Nombre de la Red',
                                      maxlength=150,
                                      size=30,
                                      label_msgid="label_entry_title",
                                      description_msgid="help_entry_title",
                                      i18n_domain="guegue.alcaldias",
                                      description='')),
    atapi.StringField('description',
                searchable=1,
                isMetadata=0,
                accessor='Description',
                widget=atapi.TextAreaWidget(label='Breve descripcion',
                                      label_msgid="label_entry_description",
                                      description_msgid="help_entry_description",
                                      i18n_domain="guegue.alcaldias",
                                      description='Entre una breve descripción del red.')),
    atapi.FileField('adjunto',
              searchable=0,
              required=0,
              widget=atapi.FileWidget(label='Archivo adjunto',
                                label_msgid="label_entry_adjunto",
                                description_msgid="help_entry_adjunto",
                                i18n_domain="guegue.alcaldias",
                                description='Puede adjuntar un archivo relacionado a la red.')),
    atapi.ImageField('image',
              searchable=0,
              required=0,
              accessor='Image',
              widget=atapi.ImageWidget(label='Imagen',
                                label_msgid="label_entry_image",
                                description_msgid="help_entry_image",
                                i18n_domain="guegue.alcaldias",
                                threshold=204800,
                                description='Puede adjuntar una imagen relacionada a la red.')),
    atapi.TextField('body',
              searchable=1,
              required=0,
              primary=1,
              default_content_type='text/html',
              default_output_type='text/html',
              allowable_content_types=('text/plain','text/structured', 'text/html', 'text/restructured'),
              widget=atapi.RichWidget(label='Texto',
                                label_msgid="label_entry_body",
                                description_msgid="help_entry_body",
                                i18n_domain="guegue.alcaldias",
                                description="Descripcion de la informacion de las redes de la asociacion...")),
    atapi.StringField('web',
                searchable=1,
                isMetadata=0,
                widget=atapi.StringWidget(label='Web',
                                      maxlength=400,
                                      size=60,
                                      label_msgid="label_entry_web",
                                      description_msgid="help_entry_web",
                                      i18n_domain="guegue.alcaldias",
                                      description='')),
))

# Set storage on fields copied from ATContentTypeSchema, making sure
# they work well with the python bridge properties.

#RedSchema['title'].storage = atapi.AnnotationStorage()
#RedSchema['description'].storage = atapi.AnnotationStorage()

schemata.finalizeATCTSchema(RedSchema, moveDiscussion=False)

class Red(base.ATCTContent):
    """Tipo de datos para redes"""
    implements(IRed)

    portal_type = "Red"
    schema = RedSchema

    #title = atapi.ATFieldProperty('title')
    #description = atapi.ATFieldProperty('description')
    def tag(self, **kwargs):
        """Generate image tag using the api of the ImageField
        """
        return self.getField('image').tag(self, **kwargs)

atapi.registerType(Red, PROJECTNAME)
